﻿using System;
using System.Collections.Generic;

namespace SLS.ExClassLib.MultiThreading.DataStructures.Tree
{
    [Serializable]
    public class TreeNodeList<T> : List<TreeNode<T>>
    {
        public TreeNode<T> Parent;

        public TreeNodeList(TreeNode<T> parent)
        {
            Parent = parent;
        }

        public new TreeNode<T> Add(TreeNode<T> node)
        {
            base.Add(node);
            node.Parent = Parent;
            return node;
        }

        public TreeNode<T> Add(T Value)
        {
            var Node = new TreeNode<T>(Parent) {Value = Value};
            return Node;
        }

        public new void Remove(TreeNode<T> node)
        {
            if (node != null)
            {
                node.Parent = null;
            }
            base.Remove(node);
        }

        public override string ToString()
        {
            return "Count=" + Count;
        }
    }
}